New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix staticcheck failures for pkg/proxy/... #81886
Fix staticcheck failures for pkg/proxy/... #81886
Conversation
Hi @praseodym. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @lavalamp |
/ok-to-test |
cf4fba6
to
65b6a48
Compare
/retest |
15112b7
to
0973b8a
Compare
/retest |
0973b8a
to
3499a27
Compare
/assign |
2b8a014
to
02bea71
Compare
// Not printing these comments, can reduce size of iptables (in case of large | ||
// number of endpoints) even by 40%+. So if total number of endpoint chains | ||
// is large enough, we simply drop those comments. | ||
if proxier.endpointChainsNumber > endpointChainsNumberThreshold { | ||
return | ||
return args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment above suggests that not returning the args was an explicit decision. I'm not sure that re-adding them is the right choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need return args
here, otherwise on L1187 in this file will replace args
by nil - see #81886 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed in #81563
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wait for that PR to merge?
pkg/proxy/iptables/proxier_test.go
Outdated
-A KUBE-SVC-3WUAALNGPYZZAWAD -j | ||
-A -s 10.0.1.3/32 -j KUBE-MARK-MASQ | ||
-A -m -p -j DNAT --to-destination 10.0.1.3:80 | ||
-A KUBE-SVC-3WUAALNGPYZZAWAD -m comment --comment ns1/svc1: -m statistic --mode random --probability 0.33333 -j |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned before, it makes sense that they comment sections indeed bloat the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment in the code there says "So if total number of endpoint chains is large enough, we simply drop those comments" and this small test doesn't exceed the threshold for not adding comments.
The code for adding comments was broken though, as described in #81886 (comment).
@@ -290,7 +290,7 @@ func (udp *udpProxySocket) proxyClient(cliAddr net.Addr, svrConn net.Conn, activ | |||
klog.Errorf("SetDeadline failed: %v", err) | |||
break | |||
} | |||
n, err = udp.WriteTo(buffer[0:n], cliAddr) | |||
_, err = udp.WriteTo(buffer[0:n], cliAddr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we ignoring this output? Is the linter complaining that it is not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, from the commit message:
pkg/proxy/userspace/proxysocket.go:293:3: this value of n is never used (SA4006)
@@ -99,26 +97,6 @@ type Proxier struct { | |||
// assert Proxier is a proxy.Provider | |||
var _ proxy.Provider = &Proxier{} | |||
|
|||
// A key for the portMap. The ip has to be a string because slices can't be map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these pieces removed because they are not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, from the commit message:
pkg/proxy/winuserspace/proxier.go:88:2: field portMapMutex is unused (U1000)
pkg/proxy/winuserspace/proxier.go:112:2: field owner is unused (U1000)
pkg/proxy/winuserspace/proxier.go:113:2: field socket is unused (U1000)
(exact line numbers are different due to rebase / other changes)
@@ -1184,7 +1184,7 @@ func (proxier *Proxier) syncProxyRules() { | |||
args = append(args[:0], | |||
"-A", string(svcChain), | |||
) | |||
proxier.appendServiceCommentLocked(args, svcNameString) | |||
args = proxier.appendServiceCommentLocked(args, svcNameString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change means that the return value of appendServiceCommentLocked
was previously not used, so comments were never added. PR #81563 was also opened to address this, but because this was also caught by staticcheck I have also fixed it in this PR.
02bea71
to
e1a5501
Compare
Rebased and updated to fix some new staticcheck failures (see PR description or commit message for a complete list). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 comment for fixup
// Not printing these comments, can reduce size of iptables (in case of large | ||
// number of endpoints) even by 40%+. So if total number of endpoint chains | ||
// is large enough, we simply drop those comments. | ||
if proxier.endpointChainsNumber > endpointChainsNumberThreshold { | ||
return | ||
return args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed in #81563
Errors from staticcheck: pkg/proxy/healthcheck/proxier_health.go:55:2: field port is unused (U1000) pkg/proxy/healthcheck/proxier_health.go:162:20: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) pkg/proxy/healthcheck/service_health.go:166:20: printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006) pkg/proxy/iptables/proxier.go:737:2: this value of args is never used (SA4006) pkg/proxy/iptables/proxier.go:737:15: this result of append is never used, except maybe in other appends (SA4010) pkg/proxy/iptables/proxier.go:1287:28: this result of append is never used, except maybe in other appends (SA4010) pkg/proxy/userspace/proxysocket.go:293:3: this value of n is never used (SA4006) pkg/proxy/winkernel/metrics.go:74:6: func sinceInMicroseconds is unused (U1000) pkg/proxy/winkernel/metrics.go:79:6: func sinceInSeconds is unused (U1000) pkg/proxy/winuserspace/proxier.go:94:2: field portMapMutex is unused (U1000) pkg/proxy/winuserspace/proxier.go:118:2: field owner is unused (U1000) pkg/proxy/winuserspace/proxier.go:119:2: field socket is unused (U1000) pkg/proxy/winuserspace/proxysocket.go:620:4: this value of n is never used (SA4006)
e1a5501
to
a54e5ce
Compare
Thanks! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: praseodym, thockin The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
2 similar comments
/retest |
/retest |
What type of PR is this?
/kind cleanup
/priority important-longterm
/sig network
What this PR does / why we need it:
Cleanup the
pkg/proxy/...
issues identified by staticcheck in #81189:Which issue(s) this PR fixes:
#36858, #81657
Special notes for your reviewer:
I'm not sure about the removal of unused fields in
pkg/proxy/winuserspace/proxier.go
, hopefully CI will catch any issues that I missed(I couldn't figure out how to do a cross build for only Windows).Also, this PR overlaps with PR #81563 because that problem was caught by staticcheck as well. I'm happy to rebase once that PR is merged.
Does this PR introduce a user-facing change?: